package com.zxw.mvpproject.mvp;

import android.content.Context;

import com.google.gson.GsonBuilder;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * 创建时间 ：2018/5/3.
 * 创建人 ：${zxw}.
 * 功能描述：
 */

public class RetrofitHelper {

    private Context mContext;
    private static RetrofitHelper instance = null;
    private RetrofitService retofitService;
    private Retrofit mRetrofit;
    OkHttpClient client = new OkHttpClient();

    public static RetrofitHelper getInstance(Context context) {
        if (instance == null) {
            instance = new RetrofitHelper(context);
        }
        return instance;
    }

    public RetrofitHelper(Context context) {
        mContext = context;
        init();
    }

    private void init() {
        restApp();
    }

    private void restApp() {
        mRetrofit = new Retrofit.Builder()
                .baseUrl("https://api.douban.com/v2/")
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create(new GsonBuilder().create()))
                .client(client)
                .build();
    }

    public RetrofitService getRetrofitService(){
        return mRetrofit.create(RetrofitService.class);
    }

}
